package com.example.medioplayer;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.medioplayer.R;

/**
 * Created by 快手 on 2017/7/3.
 */

public class TitleBar extends RelativeLayout {
    private ImageView imageView;
    private TextView title;

    public TitleBar(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.view_texttitle, this);
        imageView = (ImageView) findViewById(R.id.vt_img);
        title = (TextView) findViewById(R.id.vt_title);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TitleBar);
        int count = typedArray.getIndexCount();
        for (int i = 0; i < count; i++) {
            int attrName = typedArray.getIndex(i);
            switch (attrName) {
                case R.styleable.TitleBar_title_img:
                    imageView.setImageResource(typedArray.getResourceId(attrName, R.mipmap.ic_launcher));
                    break;
                case R.styleable.TitleBar_title_name:
                    title.setText(typedArray.getString(attrName));
                    break;
            }
        }
        typedArray.recycle();

    }

    public void steLeftImgClickListener(OnClickListener onClickListener) {
        imageView.setOnClickListener(onClickListener);
    }

    public void setTitle(String title1) {
        title.setText(title1);
    }
}
